<!--
 * @Description: Description
 * @Author: Yongchao Wang
 * @Date: 2020-09-10 08:37:58
 * @LastEditors: Yongchao Wang
 * @LastEditTime: 2020-09-11 09:00:04
-->
<template>
  <!-- optionAPI -->
  <div class="hello">
    <input type="number" v-model="num1" @keyup="add" />
    <span>+</span>
    <input type="number" v-model="num2" @keyup="add" />
    <span>=</span>
    {{result}}
  </div>
  <!-- Composition API ref-->
  <!-- <div>
    <input type="number" v-model="num3" @keyup="add1">
    <span>+</span>
    <input type="number" v-model="num4" @keyup="add1">
    <span>=</span>
    {{result1}}
  </div>-->
  <!-- Composition API reactive-->
  <!-- <div>
    <input type="number" v-model="state.num3" @keyup="add1">
    <span>+</span>
    <input type="number" v-model="state.num4" @keyup="add1">
    <span>=</span>
    {{state.result1}}
  </div>-->
</template>

<script>
import {
  ref,
  onMounted,
  onUnmounted,
  onUpdated,
  onRenderTracked,
  onRenderTriggered,
  reactive,
} from "vue";
const state = reactive({ num3: 0, num4: 0, result1: 0 });
function add1() {
  state.result1 = parseInt(state.num3) + parseInt(state.num4);
}
export default {
  name: "HelloWorld",
  props: {
    msg: String,
  },
  data() {
    return {
      num1: 0,
      num2: 0,
      result: 0,
    };
  },
  // Composition API ref
  // setup(){
  //   const num3 = ref(0)
  //   const num4 = ref(0)
  //   const result1 = ref(0)
  //   function add1(){
  //     result1.value = parseInt(num3.value) + parseInt(num4.value)
  //   }
  //   return {
  //     num3,num4,result1,add1
  //   }
  // },
  // Composition API reactive
  setup() {
    onMounted(() => {
      console.log("onMounted");
    });
    onUnmounted(() => {
      console.log("onUnmounted");
    });
    onUpdated(() => {
      console.log("onUpdated");
    });
    onRenderTracked((e) => {
      console.log("onRenderTracked" + e);
    });
    onRenderTriggered((e) => {
      console.log("onRenderTriggered" + e);
    });
  },
  methods: {
    add() {
      this.result = parseInt(this.num1) + parseInt(this.num2);
    },
  },
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h3 {
  margin: 40px 0 0;
}
ul {
  list-style-type: none;
  padding: 0;
}
li {
  display: inline-block;
  margin: 0 10px;
}
a {
  color: #42b983;
}
</style>
